/**
 * Created with IntelliJ IDEA.
 * User: Christian Dadswell
 * Date: 30/03/13
 * Time: 07:43
 */
public class functions_Strings {

    public static String ReturnShortStationName(String bbcStationName) {
        String shortenedStationName = bbcStationName.toLowerCase().replaceAll("\\s","");
        return shortenedStationName;
    }

    // STRING METHODS
    public static void print(String msg, Object... args) {
        System.out.println(String.format(msg, args));
    }

    public static String trim(String s, int width) {
        if (s.length() > width)
            return s.substring(0, width - 1) + ".";
        else
            return s;
    }

    public static String GetRight(String str, int len) {
        if (str == null) {
            return null;
        }
        if (len < 0) {
            return "";
        }
        if (str.length() <= len) {
            return str;
        }
        return str.substring(str.length() - len);
    }

    // Takes date as 30032013 and changes to 20130330
    public static String ReturnBBCScheduleDate(String dateAsString) {
        String bbcDate = null;
        String dd = null;
        String mm = null;
        String yyyy = null;

        yyyy = GetRight(dateAsString, 4);
        mm = Mid(dateAsString, 2, 4);
        dd = Left(dateAsString, 2);

        bbcDate = yyyy + mm + dd;

        return bbcDate;
    }

    public static String Left(String text, int length)
    {
        return text.substring(0, length);
    }

    public static String Right(String text, int length)
    {
        return text.substring(text.length() - length, length);
    }
    public static String Mid(String text, int start, int end)
    {
        return text.substring(start, end);
    }

    public static String Mid(String text, int start)
    {
        return text.substring(start, text.length() - start);
    }
}
